package handler;

import automakelist.equallydistributed;
import automakelist.examsdays;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.timeloveboy.moeserver.DefaultHandle;
import com.github.timeloveboy.moeserver.IHttpRequest;
import com.github.timeloveboy.moeserver.IHttpResponse;
import com.github.timeloveboy.utils.Log;
import com.github.timeloveboy.utils.StreamUtil;
import config.Config;
import data.staticdata;
import model.Week;

import java.io.IOException;
import java.util.Date;

/**
 * Created by root on 17-6-17.
 */

public class config extends DefaultHandle {
    @Override
    public void GET(IHttpRequest req, IHttpResponse resp) throws IOException {

        Config c = new Config();
        c.coach_count = 3;
        c.student_count = 20;
        c.day_h_max = 4;
        c.week_h_max = 20;
        c.subject2_h = 100;
        c.studentcount_oncar = 2;
        c.workingday = Week.defaultworkingday;


        JSON.toJSONString(c);
        staticdata.computing = new equallydistributed();
        staticdata.computing.newmaker(c, new Date());
        resp.write("");
    }

    public void POST(IHttpRequest req, IHttpResponse resp) throws IOException {
        String reqbody = StreamUtil.getBody(req.getBody());
        Log.v(reqbody);
        Config c = JSONObject.parseObject(reqbody, Config.class);
        staticdata.computing = new examsdays();
        staticdata.computing.newmaker(c, new Date());
        resp.write("");
    }
}